package com.dreamstations.changshads.fragment;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.View;
import android.view.ViewGroup;

import com.dreamstations.changshads.R;
import com.dreamstations.changshads.activity.ArticleDetailActivity;
import com.dreamstations.changshads.activity.ArticleDetail_WebActivity;
import com.dreamstations.changshads.adapter.DSRvAdapter;
import com.dreamstations.changshads.entity.WorkBean;
import com.dreamstations.changshads.util.DSRequest;
import com.dreamstations.changshads.util.RequestType;
import com.zhy.base.adapter.ViewHolder;
import com.zhy.base.adapter.recyclerview.OnItemClickListener;

public class Work_Introduction_Frag extends BaseFragmentForHome<WorkBean> {

    public Work_Introduction_Frag(){}


    @SuppressLint("ValidFragment")
    public Work_Introduction_Frag(String title, @RequestType String reqType, int category){
        Bundle bundle=new Bundle();
        bundle.putString("title",title);
        bundle.putString("reqType",reqType);
        bundle.putInt(PARAM_TYPEID,category);
        setArguments(bundle);
    }

    @SuppressWarnings("WrongConstant")
    @NonNull
    @Override
    public DSRequest getDsRequest() {
        Bundle bundle=getArguments();
        return new DSRequest()
                .type(bundle.getString("reqType"))
                .addParams(PARAM_TYPEID,String.valueOf(bundle.getInt(PARAM_TYPEID)))
                .setTag(Work_Introduction_Frag.this);
    }

    @NonNull
    @Override
    public DSRvAdapter.RvSupport<WorkBean> getItem() {
        return new DSRvAdapter.RvSupport<WorkBean>(){

            @Override
            public int getItemViewType(WorkBean data) {
                return 0;
            }

            @Override
            public ViewHolder createHolder(Context context, ViewGroup parent, int viewType) {
                return ViewHolder.get(context,null,parent, R.layout.work_item,-1);
            }

            @Override
            public void convert(ViewHolder holder, WorkBean data) {
                holder.setText(R.id.textView3,data.getTitle());
            }
        };
    }

    @Override
    public OnItemClickListener getOnItemClickListener() {
        return new OnItemClickListener<WorkBean>() {
            @Override
            public void onItemClick(ViewGroup parent, View view, WorkBean o, int position) {
                Bundle bundle=new Bundle();
                bundle.putSerializable("work",o);
                if(o.getTemplate()==1){
                    Intent intent=new Intent(getActivity(), ArticleDetail_WebActivity.class);
                    intent.putExtras(bundle);
                    startActivity(intent);
                }else {
                    Intent intent=new Intent(getActivity(), ArticleDetailActivity.class);
                    intent.putExtras(bundle);
                    startActivity(intent);
                }
            }

            @Override
            public boolean onItemLongClick(ViewGroup parent, View view, WorkBean o, int position) {
                return false;
            }
        };
    }

    @Override
    public DSRvAdapter.RvSupport getHeader() {
        return null;
    }

    @Override
    public boolean getEnablePullLoadMore() {
        return true;
    }
}